package logic

import (
	"context"
	"errors"
	"hema-fresh/hemarpc/models/mysql"

	"hema-fresh/hemarpc/hemarpc"
	"hema-fresh/hemarpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDelLogic {
	return &ProductDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 删除
func (l *ProductDelLogic) ProductDel(in *hemarpc.ProductDelRequest) (*hemarpc.ProductDelResponse, error) {
	// todo: add your logic here and delete this line
	var hema mysql.HemaProduct
	if err := hema.ProductDetail(mysql.DB, in.HemaProductId); err != nil {
		return nil, errors.New("不存在该商品，删除失败")
	}

	err := hema.ProductDel(mysql.DB, in.HemaProductId)
	if err != nil {
		return nil, err
	}

	return &hemarpc.ProductDelResponse{}, nil
}
